package com.sky.action;

import com.sky.model.BaseModel;
import com.sky.model.--CLASS_NAME--;
import com.sky.service.--CLASS_NAME--Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/--CLASS_W_NAME--")
public class --CLASS_NAME--Action {

    @Autowired
    --CLASS_NAME--Service --CLASS_NAME--Service;

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(--CLASS_NAME-- record) throws IOException {
        Map<String,Object> result = new HashMap<>();
        List<BaseModel> oResult = --CLASS_NAME--Service.query(record);
        result.put("records",oResult);
        return result;
    }

    @RequestMapping("/selectbyid")
    @ResponseBody
    public Map<String,Object> selectById(--CLASS_NAME-- record) throws IOException {
        Map<String,Object> result = new HashMap<>();
        BaseModel oResult = --CLASS_NAME--Service.selectById(record.getId());
        result.put("record",oResult);
        return result;
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Map<String,Object> insert(--CLASS_NAME-- record) throws IOException {
        Map<String,Object> result = new HashMap<>();
        int oResult = --CLASS_NAME--Service.insert(record);
        result.put("record",oResult);
        return result;
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(--CLASS_NAME-- record) throws IOException {
        Map<String,Object> result = new HashMap<>();
        int oResult = --CLASS_NAME--Service.update(record);
        result.put("record",oResult);
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Map<String,Object> delete(String id) throws IOException {
        Map<String,Object> result = new HashMap<>();
        int oResult = --CLASS_NAME--Service.delete(id);
        result.put("record",oResult);
        return result;
    }

}
